package com.maze;


import java.awt.*;

import java.util.*;
import javax.swing.JFrame;

public class MakeMaze extends JFrame  {   
  	    private static int sx;
	    private static int sy;
	    private static int w_cell;
	    private static int h_cell;
	    private Graphics jg;
	    private Map<Position, CELL> map_cell;
	    
	    	    
	public MakeMaze(int size, Map<Position, CELL> map) {
		map_cell = map;
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension dim = tk.getScreenSize();
	    size = 10;
		setSize(40*size,40*size);
        Container p = getContentPane();
        setPreferredSize(new Dimension(100, 100));
		setFont(new Font("System", Font.BOLD, 14));
	    Font f = getFont();
	    FontMetrics fm = getFontMetrics(f);
		int x = fm.stringWidth("Maze");
		int y = fm.stringWidth(" ");
		int z = getWidth()/2 - (x/2);
		int w = z/y;
		String pad ="";
		pad = String.format("%"+w+"s", pad);
		setTitle(pad+"Maze8");
		setVisible(true);
        sx = dim.width/4;
		sy = dim.width/4;
		w_cell = getWidth()/size;
		h_cell = getHeight()/size;
		setLocation(new Point(sx, sy));
        setVisible(true);
        p.setBackground(Color.WHITE);
               
        
        try {
            Thread.sleep(500);
        } catch (Exception e) {
            e.printStackTrace();
        }        

        
        for (Position po : map_cell.keySet()) {
        	jg =  this.getGraphics();
            paintComponents(jg, po);	
        }
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
	}
	 public void paintComponents(Graphics g, Position po) {
	        try {
	        	Graphics2D g2 = (Graphics2D) g;
	          
	        	  switch ( map_cell.get(po)) {
	        	  case CELL_E: 
	        		  g2.setColor(Color.white);
	        		  g2.fillRect(po.getX()*w_cell, po.getY()*h_cell, w_cell, h_cell);
	        		  break;
	        	  case CELL_T: 
	        		  g2.setColor(Color.red);
	        		  g2.fillRect(po.getX()*w_cell, po.getY()*h_cell, w_cell, h_cell);
	        		  break;
	        	  case CELL_W: 
	        		  g2.setColor(Color.black);
	        		  g2.fillRect(po.getX()*w_cell, po.getY()*h_cell, w_cell, h_cell);
	        		  break;
	        	  case CELL_L: 
	        		  g2.setColor(Color.green);
	        		  g2.fillRect(po.getX()*w_cell, po.getY()*h_cell, w_cell, h_cell);
	        		  break;
	        	  }
	          
	        
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }
	

public  void DrewMaze (int size, Map<Position, CELL> map){
	new MakeMaze(size,map);
}}